/*
 * Copyright 2008 Zoundry LLC, Inc.  All Rights Reserved.
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 only, as
 * published by the Free Software Foundation.
 *
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 *
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 */
package org.zoundry.gaedt.ui.editors.application;

import java.util.List;
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.Viewer;
import org.zoundry.gaedt.core.models.application.IZGaeHandlerModel;
import org.zoundry.gaedt.core.models.application.ZGaeApplicationModel;

/**
 * An implementation of a tree content provider for the handlers in an
 * application.
 */
public class ZGaeHandlerContentProvider implements ITreeContentProvider
{
    /** The application. */
    private ZGaeApplicationModel mApplication;

    /**
     * C'tor.
     */
    public ZGaeHandlerContentProvider()
    {
    }

    /**
     * @see org.eclipse.jface.viewers.IContentProvider#dispose()
     */
    public void dispose()
    {
    }

    /**
     * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
     */
    public void inputChanged(Viewer aViewer, Object aOldInput, Object aNewInput)
    {
        setApplication((ZGaeApplicationModel) aNewInput);
    }

    /**
     * @see org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java.lang.Object)
     */
    public Object[] getChildren(Object aParentElement)
    {
        return null;
    }

    /**
     * @see org.eclipse.jface.viewers.ITreeContentProvider#getParent(java.lang.Object)
     */
    public Object getParent(Object aElement)
    {
        return null;
    }

    /**
     * @see org.eclipse.jface.viewers.ITreeContentProvider#hasChildren(java.lang.Object)
     */
    public boolean hasChildren(Object aElement)
    {
        return false;
    }

    /**
     * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
     */
    public Object[] getElements(Object aInputElement)
    {
        ZGaeApplicationModel appModel = (ZGaeApplicationModel) aInputElement;
        List<IZGaeHandlerModel> handlers = appModel.getHandlers();
        return handlers.toArray();
    }

    /**
     * @return the application
     */
    protected ZGaeApplicationModel getApplication()
    {
        return mApplication;
    }

    /**
     * @param aApplication the application to set
     */
    protected void setApplication(ZGaeApplicationModel aApplication)
    {
        mApplication = aApplication;
    }
}
